package com.cans.impl;

import com.cans.api.IObserver;
import com.cans.api.ISubject;

import java.util.ArrayList;
import java.util.List;

/**
 * 卖大米商人
 *
 * @author shenc
 * @date 2021-11-27 14:56
 **/
public class Merchant implements ISubject {

    List<IObserver> observerList = new ArrayList<>();

    private String name;

    @Override
    public void setName(String name) {
       this.name = name;
    }

    @Override
    public void addObserver(IObserver observer) {
        observerList.add(observer);
    }

    public void addGoods(){
        this.notifyAllObservers("大米进货了");
    }

    @Override
    public void notifyAllObservers(String msg) {
        for (IObserver iObserver : observerList) {
            iObserver.receive(name,msg);
        }

    }
}
